package com.cnbbx.mybatis;

import lombok.Data;

import java.util.List;

@Data
public class PageData {
    private Integer pageStartIndex = 0;
    // 当前页
    private Integer pageNumber = 1 - pageStartIndex;
    // 下一页
    private Integer nextPageNumber;
    // 前一页
    private Integer previousPageNumber;
    // 最后一页
    private Integer lastPageNumber;
    // 分页数量标准
    private Integer pageSize = 10;
    // 总数量
    private Integer count = null;
    // 前页数量
    // private Integer after_range_num = 4;
    // 后页数量
    // private Integer before_range_num = 4;
    // 当前页数据集合
    private List list;

    // public List<Integer> getPageNumList() {
    //  List<Integer> pageNumList = new ArrayList<Integer>();
    //  int to = pageNumber + before_range_num > getLastPageNumber() ? getLastPageNumber() : pageNumber + before_range_num;
    //  if (pageNumber >= after_range_num) {
    //      for (int i = pageNumber - after_range_num > 0 ? pageNumber - after_range_num : 1; i <= to; i++) {
    //          pageNumList.add(i);
    //      }
    //  } else {
    //      for (int i = 0; i < to; i++) {
    //          pageNumList.add(i);
    //      }
    //  }
    //  return pageNumList;
    // }

    public static void main(String[] a) {
        PageData pageData = new PageData();
        pageData.setPageSize(10);
        pageData.setCount(99);
        pageData.setPageNumber(9);
        System.out.println(pageData.toString());
    }

    public Integer getBegin() {
        return (pageNumber - 1) * pageSize;
    }

    public Integer getEnd() {
        return pageNumber * pageSize >= count ? count : pageNumber * pageSize;
    }

    public Integer getLastPageNumber() {
        lastPageNumber = (count - 1) / pageSize + 1 - pageStartIndex;
        return lastPageNumber;
    }

    public void setPageNumber(Integer pageNumber) {
        this.pageNumber = null == pageNumber || pageNumber <= (1 - pageStartIndex) ? (1 - pageStartIndex) : pageNumber;
        this.pageNumber = this.pageNumber > getLastPageNumber() ? getLastPageNumber() : this.pageNumber;
    }

    public Integer getNextPageNumber() {
        if (pageNumber >= (1 - pageStartIndex) && pageNumber < getLastPageNumber()) {
            nextPageNumber = pageNumber + 1;
        } else {
            nextPageNumber = getLastPageNumber();
        }
        return nextPageNumber;
    }

    public Integer getPreviousPageNumber() {
        if (pageNumber > (1 - pageStartIndex) && pageNumber <= getLastPageNumber()) {
            previousPageNumber = pageNumber - 1;
        } else {
            previousPageNumber = (1 - pageStartIndex);
        }
        return previousPageNumber;
    }

}


